package com.ssm.security.token;

import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * Created by wchen on 2017/7/12.
 */
public interface TokenManager {

    /**
     * TokenManager负责Token的生成，验证以及删除等等操作
     * 我们可以根据自己的需要比如借助Redis做缓存，或者使用JWT等等，具体可实现自己的TokenManager我们可以根据自己的需要比如借助Redis做缓存，或者使用JWT等等，具体可实现自己的TokenManager
     * Creates a new token for the user and returns its {@link TokenInfo}.
     * It may add it to the token list or replace the previous one for the user. Never returns {@code null}.
     */
    TokenInfo createNewToken(UserDetails userDetails);

    /** Removes all tokens for user. */
    //void removeUserDetails(UserDetails userDetails);

    /** Removes a single token. */
    UserDetails removeToken(String token);

    /** Returns user details for a token. */
    UserDetails getUserDetails(String token);

    /** Returns user details for a username. */
    UserDetails getUserDetailsByUsername(String username);

    /** Returns a collection with token information for a particular user. */
    Collection<TokenInfo> getUserTokens(UserDetails userDetails);


    Boolean validateToken(String token);
}
